package com.cloud.code.牛客网;

import java.util.*;

/**
 * 全排列
 */
public class Test47 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int anInt = scanner.nextInt();
            int[] nums = new int[anInt];

            for (int i = 1; i <= anInt; i++) {
                nums[i - 1] = i;
            }

            Deque<Integer> path = new ArrayDeque<Integer>();
            boolean[] used = new boolean[anInt];
            List<Integer> res = new ArrayList<>();
            dfs(nums, nums.length, 0, path, used, res);

            Collections.sort(res);
            System.out.println(res.get(1));

        }
    }

    private static void dfs(int[] nums, int len, int depth, Deque<Integer> path, boolean[] used, List<Integer> res) {
        if (len == depth) {
            System.out.println(Arrays.toString(new Deque[]{path}));
            String s = Arrays.toString(new Deque[]{path}).replaceAll("\\W+", "");
            System.out.println(s);
            res.add(Integer.parseInt(s));
            return;
        }

        for (int i = 0; i < len; i++) {
            if (used[i]) {
                continue;
            }
            path.addLast(nums[i]);
            used[i] = true;
            dfs(nums, len, depth + 1, path, used, res);
            path.removeLast();
            used[i] = false;
        }
    }

}
